﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EBAYVN.DOMAIN;

namespace EBAYVN.DAO
{
    public class EbayFuntionDao
    {
        private EBAYVNDataContext _db = new EBAYVNDataContext();
        public BiddingFuntion Get(int id)
        {
            return _db.BiddingFuntions.Where(g => g.Id.Equals(id)
                && g.Deleted.Equals(false)).SingleOrDefault();
        }

        /// <summary>
        /// Get function list
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<BiddingFuntion> GetList(int id)
        {
            return _db.BiddingFuntions.Where(g => g.Parent.Equals(id) &&
                                               g.Deleted.Equals(false)).
                                               OrderBy(f => f.Order).
                                               ToList();

        }
        
        public BiddingFuntion GetFromURL(string urlPath)
        {
            return _db.BiddingFuntions.Where(w => w.Url.ToLower().Contains(urlPath.ToLower())).Distinct().SingleOrDefault();
        }
        
    }
}
